﻿using System;
using System.Linq.Expressions;

namespace Batman.Cms.Core.Core.SimpleMaintenance.Utils
{
    public class ExpressionUtil
    {
        /// <summary>
        /// 获取表达式返回的属性的名字
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="property"></param>
        /// <returns></returns>
        public static string GetSmallHumpWord(Expression property)
        {
            switch (property.NodeType)
            {
                case ExpressionType.MemberAccess:
                    return ((MemberExpression)property).Member.Name;
                case ExpressionType.Convert:
                    return GetSmallHumpWord(((UnaryExpression)property).Operand);
                default:
                    throw new NotSupportedException(property.NodeType.ToString());
            }
        }
    }
}
